package com.aaa.worldmodel.surface.model;

import android.content.Context;
import android.opengl.Matrix;

import com.aaa.worldmodel.surface.bean.ModelData;

public abstract class Model {

    protected static final int FLOAT_SIZE = 4;
    protected final float[] mMatrix = new float[16];
    protected final float[] pMatrix = new float[16];
    protected final float[] vMatrix = new float[16];

    /**
     * 模型本身的平移缩放旋转 用于控制模型的位置大小
     */
    protected float[] scale = new float[]{1, 1, 1};
    protected float[] offset = new float[3];
    protected float[] rotate = new float[3];

    protected int programId;
    protected String vertexShaderCode;
    protected String fragmentShaderCode;

    public static float[] getOriginalMatrix() {
        return new float[]{
                1, 0, 0, 0,
                0, 1, 0, 0,
                0, 0, 1, 0,
                0, 0, 0, 1
        };
    }


    public void setMatrix(float[] mMatrix, float[] vMatrix, float[] pMatrix) {
        System.arraycopy(mMatrix, 0, this.mMatrix, 0, mMatrix.length);
        System.arraycopy(vMatrix, 0, this.vMatrix, 0, vMatrix.length);
        System.arraycopy(pMatrix, 0, this.pMatrix, 0, pMatrix.length);

        //先做模型本身的 平移/旋转/缩放, 顺序不能乱
        Matrix.translateM(this.mMatrix, 0, offset[0], offset[1], offset[2]);

        Matrix.rotateM(this.mMatrix, 0, rotate[0], 1, 0, 0);
        Matrix.rotateM(this.mMatrix, 0, rotate[1], 0, 1, 0);
        Matrix.rotateM(this.mMatrix, 0, rotate[2], 0, 0, 1);

        Matrix.scaleM(this.mMatrix, 0, scale[0], scale[1], scale[2]);
    }

    public void setScale(float scale) {
        this.scale[0] = scale;
        this.scale[1] = scale;
        this.scale[2] = scale;
    }

    public void setOffset(float offsetX, float offsetY, float offsetZ) {
        this.offset[0] = offsetX;
        this.offset[1] = offsetY;
        this.offset[2] = offsetZ;
    }

    public void setRotate(float rotateX, float rotateY, float rotateZ) {
        this.rotate[0] = rotateX;
        this.rotate[1] = rotateY;
        this.rotate[2] = rotateZ;
    }

    public void setEye(float[] eye) {

    }

    public void setLight(float[] light) {
    }

    public void setData(ModelData data) {
    }

    public abstract void onCreate(Context context);

    public abstract void onDraw();

    public abstract void onDestroy();
}
